<template>
  <div class="more-msg">
    <div class="more-msg-name">歌曲:{{ msg.name }}</div>
    <div class="each-msg" @click="next(msg)">
      <span class="icon-next"></span>
      <div>下一首播放</div>
    </div>
    <div class="each-msg" @click="collection(msg.id)">
      <span class="icon-collection"></span>
      <div>收藏到歌单</div>
    </div>
    <div class="each-msg" @click="toComment(msg.id)">
      <span class="icon-comment"></span>
      <div>评论</div>
    </div>
    <div class="each-msg" @click="toArtist(msg.artists[0].id)">
      <span class="icon-我的"></span>
      <div class="each-msg-artist">
        歌手：<artists :artists="artist"></artists>
      </div>
    </div>
    <div class="each-msg" @click="toAlbum(msg.album.id)">
      <span class="icon-专辑"></span>
      <div>专辑：{{ album.name }}</div>
    </div>
  </div>
</template>

<script lang="ts">
import { Vue, Component, Prop, Emit } from "vue-property-decorator";
import { namespace } from "vuex-class";
import Router from "vue-router";
import { MusicInfo } from "@/model/music-info.model";
import { CurrentMusic } from "@/model/current-music.model";
import { CommentType, CommonIdType } from "@/model/id-or-enum.model";
import { APIType } from "@/api";
const AppModule = namespace("app");
@Component({})
export default class MoreMsgComponent extends Vue {
  @Prop({ required: true })
  msg: MusicInfo;

  $router: Router;
  $api: APIType;

  @AppModule.State("nowMusic")
  nowMusic: CurrentMusic;

  @AppModule.Mutation("setCurrentMusicInfo")
  setCurrentMusicInfo: (music: CurrentMusic) => void;
  @AppModule.Mutation("setCommentType")
  setCommentType: (commentType: CommentType) => void;

  get artist() {
    return this.msg.artists || this.msg.ar;
  }
  get album() {
    return this.msg.album || this.msg.al;
  }
  next(music: MusicInfo) {
    const {
      artists,
      id,
      name,
      album: { picUrl },
      mp3Url,
    } = music;
    const index = this.nowMusic.index;
    const info: CurrentMusic = {
      nowArtists: artists,
      id,
      nowImgUrl: picUrl,
      nowName: name,
      nowMusicUrl: mp3Url,
      index,
    };
    this.setCurrentMusicInfo(info);
    this.hiddenAction();
  }
  @Emit("hidden")
  hiddenAction() {
    // 函数的返回值会被当成$emit()的第二个参数
  }
  collection(id: CommonIdType) {
    // TODO: 动态获取歌单ID
    const playListId = 495727117;
    this.$api.operatePlayList("add", playListId, id).then(() => {
      this.hiddenAction();
    });
  }
  toComment(id: CommonIdType) {
    this.setCommentType(CommentType.ToSong);
    this.$router.push({ path: `/comment/${id}` }).catch((err) => err);
  }
  toArtist(id: CommonIdType) {
    this.$router.push({ path: `/artist/${id}` }).catch((err) => err);
  }
  toAlbum(id: CommonIdType) {
    this.$router.push({ path: `/album/${id}` }).catch((err) => err);
  }
}
</script>

<style lang="scss" scoped>
.more-msg-name {
  height: 0.5rem;
  line-height: 0.5rem;
  font-size: 0.3rem;
  margin-left: 0.3rem;
}
.each-msg {
  display: flex;
  height: 0.6rem;
  line-height: 0.6rem;
  font-size: 0.3rem;
  margin: 0.2rem 0;
  > span {
    color: red;
    width: 1rem;
    text-align: center;
    line-height: 0.6rem;
  }
  > div {
    flex: 1;
    border-bottom: 1px solid #666;
  }
  .each-msg-artist {
    display: flex;
  }
}
</style>
